/*
 * @Author: lin_zizhuo 2297304135@qq.com
 * @Date: 2023-12-09 18:40:24
 * @LastEditors: lin_zizhuo 2297304135@qq.com
 * @LastEditTime: 2023-12-09 18:40:24
 * @FilePath: /thread_text/thread_mutex/lockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <pthread.h>

class Mutex
{
private:
    pthread_mutex_t* _plock;
public:
    void lock() { pthread_mutex_lock(_plock); }
    void unlock() { pthread_mutex_unlock(_plock); } 
    Mutex(pthread_mutex_t* plock)
        :_plock(plock) {}
    ~Mutex() {}
};

class LockGuard
{
private:
    Mutex _mutex;
public:
    LockGuard(pthread_mutex_t* plock) :_mutex(plock)
    { _mutex.lock(); }
    ~LockGuard() { _mutex.unlock(); }
};
